package com.example.pilipili.dao;

import com.example.pilipili.pojo.dto.APDto;
import com.example.pilipili.pojo.entity.AdminPrivileges;
import com.example.pilipili.pojo.entity.Privileges;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author liyv
 * @since 2023-12-01
 */
@Mapper
public interface AdminPrivilegesMapper extends BaseMapper<AdminPrivileges> {

    @Select("select a.id , a.name , a.phone " +
            "from admin a " +
            "left join admin_privileges ap on a.id = ap.aid " +
            "group by a.id")
    List<APDto> getUsers();

    @Select("select a.id, a.name, a.phone " +
            "from admin a " +
            "where a.id=#{aid}")
    APDto getUserById(@Param("aid") Integer aid);

    @Select("select p.id,p.name,p.description from admin_privileges ap " +
            "         join privileges p on ap.pid = p.id " +
            "         where ap.aid=#{aid};")
    List<Privileges> getPListByUId(@Param("aid") Integer aid);

    @Select("select p.* from  privileges p" +
            "    where id not in (select pid from admin_privileges where  aid = #{aid})")
    List<Privileges> selectByNotInAdmin(@Param("aid") int aid) ;

}
